package top.fwpsl.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.fwpsl.config.properties.RedisProperty;

import javax.annotation.PostConstruct;

/**
 * @auther: 风戏fw
 * @date: 2020/11/21
 */
@Component
public class RedisConfig {

    @Autowired
    private RedisProperty redisProperty;

    public static boolean switcher;
    public static int maxIdle;
    public static int minIdle;
    public static int maxTotal;
    public static int maxWaitMillis;
    public static int connectionTimeout;
    public static int soTimeout;
    public static int maxAttempts;
    public static String serverHost;
    public static int serverPort;

    /**
     * redis 慢日志开关
     */
    public static boolean consumeTimeSwitcher;

    /**
     * redis 慢日志阀值
     */
    public static int consumeTimeThreshold;
    public static boolean targetServerSwitcher;
    public static boolean performanceSwitcher;
    public static boolean logLoopSwitcher;
    public static boolean crashThenAccessDb;
    public static int poolMonitorAccessInterval;

    @PostConstruct
    public void init() {
        maxIdle = redisProperty.getMaxIdle();
        minIdle = redisProperty.getMinIdle();
        maxTotal = redisProperty.getMaxTotal();
        maxWaitMillis = redisProperty.getMaxWaitMillis();
        connectionTimeout = redisProperty.getConnectionTimeout();
        soTimeout = redisProperty.getSoTimeout();
        maxAttempts = redisProperty.getMaxAttempts();
        serverHost = redisProperty.getServerHost();
        serverPort = redisProperty.getServerPort();
    }
}
